package com.fxsh168.server.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.fxsh168.server.base.BaseActivity;
import com.fxsh168.server.interfaces.Constant;
import com.fxsh168.server.R;


public class SettingActivity extends BaseActivity {

    private AlertDialog dialogSet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set);

    }

    public void goModifyPassword(View view) {
        startActivity(new Intent(this, ChangePasswordActivity.class));
    }


    public void goAboutInfo(View view) {
        startActivity(new Intent(this, AboutUsActivity.class));
    }

    public void btnTuiChu(View view) {
        //用自定义dialog
        AlertDialog.Builder builderset = new AlertDialog.Builder(SettingActivity.this);
        View viewset = LayoutInflater.from(SettingActivity.this).inflate(R.layout.setdialog_layout, null);
        builderset.setView(viewset);

        TextView cacelset = (TextView) viewset.findViewById(R.id.btnCacelset);
        cacelset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogSet.dismiss();
            }
        });

        TextView btnOkset = (TextView) viewset.findViewById(R.id.btnOKset);
        btnOkset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setAction("exit_app");
                sendBroadcast(intent);
                Intent intent1 = new Intent(SettingActivity.this, LoginActivity.class);
                startActivity(intent1);
                //让对话框消失
                dialogSet.dismiss();
            }
        });

        dialogSet = builderset.create();
        dialogSet.setCanceledOnTouchOutside(true);
        dialogSet.show();

        WindowManager mset = getWindowManager();
        Display dset = mset.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams pset = dialogSet.getWindow().getAttributes(); // 获取对话框当前的参数值
        pset.height = (int) (dset.getHeight() * 0.215); // 高度设置为屏幕的0.6
        pset.width = (int) (dset.getWidth() * 0.75); // 宽度设置为屏幕的0.95
        dialogSet.getWindow().setBackgroundDrawableResource(R.drawable.shapedingdan);
        dialogSet.getWindow().setAttributes(pset);
    }
}
